package com.pai4j.zwiki.domain.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDateTime;

/**
 * 问答索引实体
 * 存储代码的问答索引和embeddings
 *
 * @author pai4j
 * @since 2025-10-12
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "pai4j_qa_index", indexes = {
        @Index(name = "idx_task_id", columnList = "taskId")
})
public class QaIndexEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 关联的分析任务ID
     */
    @Column(nullable = false, length = 64)
    private String taskId;

    /**
     * 代码片段或文档片段
     */
    @Column(nullable = false, columnDefinition = "LONGTEXT")
    private String content;

    /**
     * 内容类型：code, doc, summary, architecture
     */
    @Column(nullable = false, length = 20)
    private String contentType;

    /**
     * 关联的文件路径
     */
    @Column(length = 512)
    private String filePath;

    /**
     * 向量嵌入（JSON格式存储float数组）
     */
    @Column(columnDefinition = "LONGTEXT")
    private String embedding;

    /**
     * 元数据（JSON格式）
     */
    @Column(columnDefinition = "TEXT")
    private String metadata;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;
}

